package HCI.src;

import java.util.LinkedList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class searching extends Activity {
	 Connector a;
	 static String[][] results;
    /** Called when the activity is first created. */
    @Override
   

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
      /*  ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.time_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);*/
        Spinner SpinnerCountries;
   	 	ArrayAdapter<CharSequence> AdapterCountries;
        setContentView(R.layout.search);
 	   String[] Countries = { "1:00", "2:00", "3:00" };

	   // //////////////////Countries Spinner/////////////////////////////////
	   SpinnerCountries = (Spinner) findViewById(R.id.timing);

	   // //////////////////////////////////////////////////////////////
	   // create an arrayAdapter an assign it to the spinner
	   AdapterCountries = new ArrayAdapter<CharSequence>(this,
	   android.R.layout.simple_spinner_item);
	   AdapterCountries
	   .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	   SpinnerCountries.setAdapter(AdapterCountries);

	   int lenCountries = Countries.length;

	   for (int i = 0; i < lenCountries; i++) {
	   // test += Areas[i] + "\n";
	   AdapterCountries.add(Countries[i]);
	   }
	   ((Button)findViewById(R.id.recipeButton)).setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			
			// TODO Auto-generated method stub
			EditText recipeName = (EditText)findViewById(R.id.recipeName);
			String name = recipeName.getText().toString();
			  a=new Connector("SELECT rcpe_name FROM recipe WHERE rcpe_name LIKE '"+name+"';");
			String [][] results = a.run();
			  Intent dst=new Intent(v.getContext(),ViewResults.class);
			startActivity(dst);
		}
	});
	   
	   
	   ((Button)findViewById(R.id.cook)).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				// TODO Auto-generated method stub
				EditText ing1 = (EditText)findViewById(R.id.EditText03);
				EditText ing2 = (EditText)findViewById(R.id.EditText02);
				EditText ing3 = (EditText)findViewById(R.id.ing3);
				String in1 = ing1.getText().toString();
				String in2 = ing2.getText().toString();
				String in3 = ing3.getText().toString();
				
				a=new Connector("SELECT rcpe_name from recipe join ing_rcpe on recipe.rcpe_id = ing_rcpe.rcpe_id where ing_id = (Select ing_id from ingredient where ing_name LIKE '"+in1+"' or  '"+in2+"' or '"+in3+"');" );
				String [][] results = a.run();
				  Intent dst=new Intent(v.getContext(),ViewResults.class);
				startActivity(dst);
			}
		});
    }
}